package cn.gson.crm.model.pojos;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "Money_back_plan", schema = "CRM", catalog = "")
public class MoneyBackPlan {
    private long backId;
    private String backNumber;
    private String backState;
    private Timestamp backTime;
    private Long backMoney;
    private String backDesc;
    private String backMethod;
    private Customer customerByCustomerId;
    private Order orderByOrderId;
    private Long backChage;
    private Employee employee;
    private RefundRecord record;
    @OneToOne(mappedBy="moneyBackPlan")
    public RefundRecord getRecord() {
        return record;
    }

    public void setRecord(RefundRecord record) {
        this.record = record;
    }

    @Basic
    @Column(name = "back_chage")
    public Long getBackChage() {
        return backChage;
    }

    public void setBackChage(Long backChage) {
        this.backChage = backChage;
    }
    @ManyToOne(cascade={CascadeType.MERGE,CascadeType.REFRESH},optional=false)//可选属性optional=false,表示author不能为空。删除文章，不影响用户
    @JoinColumn(name = "back_chage",insertable = false,updatable = false)//设置在article表中的关联字段(外键)
    public Employee getEmployee() {
        return employee;
    }

    public void setEmployee(Employee employee) {
        this.employee = employee;
    }

    @ManyToOne
    @JoinColumn(name = "order_id", referencedColumnName = "order_id")
    public Order getOrderByOrderId() {
        return orderByOrderId;
    }

    public void setOrderByOrderId(Order orderByOrderId) {
        this.orderByOrderId = orderByOrderId;
    }

    @Id
    @Column(name = "back_id")
    @GeneratedValue(generator = "seq",strategy = GenerationType.SEQUENCE)
    //定义一个序列生成器
    @SequenceGenerator(name = "seq",sequenceName = "crm",
            initialValue = 1,allocationSize = 1)
    public long getBackId() {
        return backId;
    }

    public void setBackId(long backId) {
        this.backId = backId;
    }

    @Basic
    @Column(name = "back_number")
    public String getBackNumber() {
        return backNumber;
    }

    public void setBackNumber(String backNumber) {
        this.backNumber = backNumber;
    }

    @Basic
    @Column(name = "back_state")
    public String getBackState() {
        return backState;
    }

    public void setBackState(String backState) {
        this.backState = backState;
    }

    @Basic
    @Column(name = "back_time")
    public Timestamp getBackTime() {
        return backTime;
    }

    public void setBackTime(Timestamp backTime) {
        this.backTime = backTime;
    }

    @Basic
    @Column(name = "back_money")
    public Long getBackMoney() {
        return backMoney;
    }

    public void setBackMoney(Long backMoney) {
        this.backMoney = backMoney;
    }

    @Basic
    @Column(name = "back_desc")
    public String getBackDesc() {
        return backDesc;
    }

    public void setBackDesc(String backDesc) {
        this.backDesc = backDesc;
    }

    @Basic
    @Column(name = "back_method")
    public String getBackMethod() {
        return backMethod;
    }

    public void setBackMethod(String backMethod) {
        this.backMethod = backMethod;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        MoneyBackPlan that = (MoneyBackPlan) o;
        return backId == that.backId &&
                Objects.equals(backNumber, that.backNumber) &&
                Objects.equals(backState, that.backState) &&
                Objects.equals(backTime, that.backTime) &&
                Objects.equals(backMoney, that.backMoney) &&
                Objects.equals(backDesc, that.backDesc) &&
                Objects.equals(backMethod, that.backMethod);
    }

    @Override
    public int hashCode() {
        return Objects.hash(backId, backNumber, backState, backTime, backMoney, backDesc, backMethod);
    }

    @ManyToOne
    @JoinColumn(name = "customer_id", referencedColumnName = "customer_id")
    public Customer getCustomerByCustomerId() {
        return customerByCustomerId;
    }

    public void setCustomerByCustomerId(Customer customerByCustomerId) {
        this.customerByCustomerId = customerByCustomerId;
    }
}
